<%--
  Created by IntelliJ IDEA.
  User: dzw
  Date: 2018/3/20
  Time: 16:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String realPath = request.getServletContext().getRealPath("/");
  String newPath = realPath.replace('\\', '/');
%>


<style>
  table td,table th{
    text-align: center;
    vertical-align: middle !important;
    /*font-weight: normal !important;*/
    font-size: 12px !important;
  }

  #summaryTbody a{
    text-decoration: underline;
  }

  table a{
    color: #346edc;
  }
</style>

<div id="page-content">
  <div class="row">
    <div class="col-lg-12">
      <div class="panel">
        <div class="panel-heading">
          <h3 class="panel-title" style="display: inline">2018年杨浦区居委会主任换届情况统计表</h3>
          <a id="exportZr" class="btn btn-info btn-sm pull-right" href="javascript:void(0)" style="height: 30px;margin-top: 10px">
            <i class="ti-download"> </i> 导出
          </a>
        </div>
        <div class="panel-body">

          <table class="table table-bordered table-condensed table-striped">
            <thead>
            <tr>
              <th width="3%" rowspan="4">序号</th>
              <th width="6%" rowspan="4">街道（镇）</th>
              <th width="4%" rowspan="4">居委会数</th>
              <th width="4%" rowspan="4">拟参加换届选举居委会数</th>
              <th colspan="18">居委会主任情况</th>
            </tr>
            <tr>
              <th width="4.5%" rowspan="3">实有人数</th>
              <th width="4.5%" rowspan="3">一肩挑人数</th>
              <th width="4.5%" rowspan="3">拟一肩挑人数</th>
              <th rowspan="2" colspan="2">女性</th>
              <th colspan="3">年龄</th>
              <th colspan="4">学历</th>
              <th colspan="6">政治面貌情况</th>
            </tr>
            <tr>
              <th width="4.5%" rowspan="2">平均年龄</th>
              <th width="4.5%" rowspan="2">就业年龄段人数</th>
              <th width="4.5%" rowspan="2">比例</th>
              <th colspan="2">大专及以上</th>
              <th colspan="2">其中：全日制</th>
              <th colspan="2">中共党员</th>
              <th colspan="2">其中：男</th>
              <th colspan="2">其中：女</th>
            </tr>
            <tr>
              <th width="4.5%">人数</th>
              <th width="4.5%">比例</th>
              <th width="4.5%">人数</th>
              <th width="4.5%">比例</th>
              <th width="4.5%">人数</th>
              <th width="4.5%">比例</th>
              <th width="4.5%">人数</th>
              <th width="4.5%">比例</th>
              <th width="4.5%">57岁以下人数</th>
              <th width="4.5%">比例</th>
              <th width="4.5%">52岁以下人数</th>
              <th width="4.5%">比例</th>
            </tr>
            </thead>
            <tbody id="summaryTbody">
            <c:forEach items="${data}" var="item" varStatus="index">
              <tr>
                <td>${index.index+1}</td>
                <td>${item.street}</td>
                <td><a href="javascript:void(0)" onclick="openStreetDetail('${item.streetId}','${item.street}')">${item.streetNum}</a></td>
                <td>${item.residentCount}</td>
                <td>${item.personCount}</td>
                <td><a href="javascript:void(0)" onclick="openZrYijiantiao('${item.streetId}','${item.street}')">${item.yijiantiao}</a></td>
                <td><a href="javascript:void(0)" onclick="openZrNiyijiantiao('${item.streetId}','${item.street}')">${item.niyijiantiao}</a></td>
                <td><a href="javascript:void(0)" onclick="openNvPerson('${item.streetId}','${item.street}')">${item.nvxing}</a></td>
                <td>${item.nvxingBi}</td>
                <td>${item.ageAvg}</td>
                <td>${item.jiuye}</td>
                <td>${item.jiuyeBi}</td>
                <td><a href="javascript:void(0)" onclick="openDaZhuanPerson('${item.streetId}','${item.street}')">${item.dazhuan}</a></td>
                <td>${item.dazhuanBi}</td>
                <td>${item.quanrizhi}</td>
                <td>${item.quanrizhiBi}</td>
                <td>${item.dangyuan}</td>
                <td>${item.dangyuanBi}</td>
                <td>${item.dangyuannan}</td>
                <td>${item.dangyuannanBi}</td>
                <td>${item.dangyuannv}</td>
                <td>${item.dangyuannvBi}</td>
              </tr>
            </c:forEach>
            <tr id="tableNum">
              <td colspan="2">合计</td>
              <td id="td1"></td>
              <td id="td2"></td>
              <td id="td3"></td>
              <td id="td4"></td>
              <td id="td5"></td>
              <td id="td6"></td>
              <td id="td7"></td>
              <td id="td8"></td>
              <td id="td9"></td>
              <td id="td10"></td>
              <td id="td11"></td>
              <td id="td12"></td>
              <td id="td13"></td>
              <td id="td14"></td>
              <td id="td15"></td>
              <td id="td16"></td>
              <td id="td17"></td>
              <td id="td18"></td>
              <td id="td19"></td>
              <td id="td20"></td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>

  </div>
</div>

<form action="<%=path%>/com/export/downloadZr" id="zr_form" method="post">
  <input name="filepath" id="filepath" type="hidden" value="" />
  <input name="fileFullName" id="fileFullName" type="hidden"/>
  <input name="zrData" id="zrData" type="hidden"/>
</form>

<script>
  $(function(){
    $("#tableNum td").each(function(index){
      if(index!=0){
        var trs = $("#summaryTbody tr");
        var a=0;
        for(var i=0;i<trs.length-1;i++){
          var nu=trs.eq(i).find("td").eq(index+1).text();
          if(nu.indexOf("%")>=0){
            var number = toPoint(nu);
            a+=parseFloat(number);
          }else{
            a+=parseInt(nu);
          }
        }

        if(index==7 || index==10 || index==12 || index==14 || index==16 || index==18 || index==20){
//          $(this).text(toPercent(a/12)); //计算错误
        }else if(index==8 || index==22){
          var size = $("#summaryTbody tr").size()-1;
          $(this).text((a/size).toFixed(2));
        }else{
          $(this).text(a);
        }
      }

    });

    //计算几个百分数的总和
    var juminqu = parseInt($("#td3").text());
    $("#td7").text(juminqu==0?"0%":toPercent(parseInt($("#td6").text()) / juminqu));
    $("#td10").text(juminqu==0?"0%":toPercent(parseInt($("#td9").text()) / juminqu));
    $("#td12").text(juminqu==0?"0%":toPercent(parseInt($("#td11").text()) / juminqu));
    $("#td14").text(juminqu==0?"0%":toPercent(parseInt($("#td13").text()) / juminqu));
    $("#td16").text(juminqu==0?"0%":toPercent(parseInt($("#td15").text()) / juminqu));

    var dangyuan = parseInt($("#td15").text());
    $("#td18").text(dangyuan==0?"0%":toPercent(parseInt($("#td17").text()) / dangyuan));
    $("#td20").text(dangyuan==0?"0%":toPercent(parseInt($("#td19").text()) / dangyuan));
  });

  //百分数转小数
  function toPoint(percent){
    var str=percent.replace("%","");
    str= str/100;
    return str;
  }

  //小数转百分数
  function toPercent(point){
    var str=Number(point*100).toFixed(1);
    str+="%";
    return str;
  }

  //居民区党组织数（打开街道下面的居民区列表）
  function openStreetDetail(streetId,streetName){
    if(streetId!="" && streetId!=null){
      __open_dialog_form_read(streetName,"<%=path%>/com/person/openStreet?streetId="+streetId);
    }else{
      __toastr_error("未找到此街道的相关信息");
    }
  }

  //打开人员详情 -- 女性链接
  function openNvPerson(streetId,streetName){
    if(streetId!="" && streetId!=null){
      var name = "主任 性别";
      __open_dialog_form_read(streetName+"-"+name,"<%=path%>/com/director/openPerson?streetId="+streetId);
    }else{
      __toastr_error("未找到相关数据");
    }
  }

  //打开人员列表 -- 大专链接
  function openDaZhuanPerson(streetId,streetName){
    if(streetId!="" && streetId!=null){
      var name = "主任 学历";
      __open_dialog_form_read(streetName+"-"+name,"<%=path%>/com/director/openDaZhuanPerson?streetId="+streetId);
    }else{
      __toastr_error("未找到相关数据");
    }
  }

  //打开一肩挑人员
  function openZrYijiantiao(streetId,streetName){
    if(streetId!="" && streetId!=null){
      var name = "主任 一肩挑";
      __open_dialog_form_read(streetName+"-"+name,"<%=path%>/com/person/openZrYijiantiao?streetId="+streetId);
    }else{
      __toastr_error("未找到相关数据");
    }
  }

  //打开拟一肩挑人员
  function openZrNiyijiantiao(streetId,streetName){
    if(streetId!="" && streetId!=null){
      var name = "主任 一肩挑";
      __open_dialog_form_read(streetName+"-"+name,"<%=path%>/com/person/openZrNiyijiantiao?streetId="+streetId);
    }else{
      __toastr_error("未找到相关数据");
    }
  }

  //导出 书记统计表
  $("#exportZr").click(function(){

    var zrList = new Array();
    $("#summaryTbody tr").each(function(i){
      var zr = new Object();
      if((i+1)!=$("#summaryTbody tr").size()){ //前面的几行...
        zr.td0 = $(this).find("td").eq(0).text();
        zr.td1 = $(this).find("td").eq(1).text();
        zr.td2 = $(this).find("td").eq(2).text();
        zr.td3 = $(this).find("td").eq(3).text();
        zr.td4 = $(this).find("td").eq(4).text();
        zr.td5 = $(this).find("td").eq(5).text();
        zr.td6 = $(this).find("td").eq(6).text();
        zr.td7 = $(this).find("td").eq(7).text();
        zr.td8 = $(this).find("td").eq(8).text();
        zr.td9 = $(this).find("td").eq(9).text();
        zr.td10 = $(this).find("td").eq(10).text();
        zr.td11 = $(this).find("td").eq(11).text();
        zr.td12 = $(this).find("td").eq(12).text();
        zr.td13 = $(this).find("td").eq(13).text();
        zr.td14 = $(this).find("td").eq(14).text();
        zr.td15 = $(this).find("td").eq(15).text();
        zr.td16 = $(this).find("td").eq(16).text();
        zr.td17 = $(this).find("td").eq(17).text();
        zr.td18 = $(this).find("td").eq(18).text();
        zr.td19 = $(this).find("td").eq(19).text();
        zr.td20 = $(this).find("td").eq(20).text();
        zr.td21 = $(this).find("td").eq(21).text();
      }else{ //合计
        zr.td0 = $(this).find("td").eq(0).text();;
        zr.td1 = "";
        zr.td2 = $(this).find("td").eq(1).text();
        zr.td3 = $(this).find("td").eq(2).text();
        zr.td4 = $(this).find("td").eq(3).text();
        zr.td5 = $(this).find("td").eq(4).text();
        zr.td6 = $(this).find("td").eq(5).text();
        zr.td7 = $(this).find("td").eq(6).text();
        zr.td8 = $(this).find("td").eq(7).text();
        zr.td9 = $(this).find("td").eq(8).text();
        zr.td10 = $(this).find("td").eq(9).text();
        zr.td11 = $(this).find("td").eq(10).text();
        zr.td12 = $(this).find("td").eq(11).text();
        zr.td13 = $(this).find("td").eq(12).text();
        zr.td14 = $(this).find("td").eq(13).text();
        zr.td15 = $(this).find("td").eq(14).text();
        zr.td16 = $(this).find("td").eq(15).text();
        zr.td17 = $(this).find("td").eq(16).text();
        zr.td18 = $(this).find("td").eq(17).text();
        zr.td19 = $(this).find("td").eq(18).text();
        zr.td20 = $(this).find("td").eq(19).text();
        zr.td21 = $(this).find("td").eq(20).text();
        zr.td22 = $(this).find("td").eq(21).text();
      }
      zrList.push(zr);
    });
    var jsonVal = JSON.stringify(zrList);
    $("#zrData").val(jsonVal);

    $('#filepath').val("<%=newPath%>/file/"+encodeURIComponent("zr.xls") );
    $('#fileFullName').val(encodeURIComponent("zr.xls"));
    $("#zr_form").submit();

    <%--__ajax_post("<%=path%>/com/export/downloadSj",{filepath:$("#filepath").val(),fileFullName:$("#fileFullName").val(),sjData:$("#sjData").val()});--%>
  });

</script>